import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

/**
 * This is a properties learning test class
 * 这是一个properties学习测试类
 * 转自菜鸟教程
 * http://www.runoob.com/java/java-properties-class.html
 *
 */
public class PropertiesTest {

    public static void main(String args[]) {
        Properties capitals = new Properties();
        Set states;
        String str;

        //Write key pairs to a list useing .put("Object key","Object Value") method
        //使用.put（“键”，“值”）方法将键值对写入list
        //capitals.put("对象的键","对象的值");
        capitals.put("Illinois", "Springfield");
        capitals.put("Missouri", "Jefferson City");
        capitals.put("Washington", "Olympia");
        capitals.put("California", "Sacramento");
        capitals.put("Indiana", "Indianapolis");

        //Use the hashtable method put the key pairs
        // 调用 Hashtable 的方法 put键值对
        capitals.setProperty("Las Vegas","Nevada");

        // Show all states and capitals in hashtable.
        //展示所有的states（州）和capitals（资本）在hash表
        states = capitals.keySet(); // get set-view of keys用states来取得capitals的所有键值
        Iterator itr = states.iterator();
        while(itr.hasNext()) {
            str = (String) itr.next();
            //通过使用.getProperty()方法搜索属性
            System.out.println("The capital of " +
                    str + " is " + capitals.getProperty(str) + ".");
        }
        System.out.println();

        // look for state not in list -- specify default
        //观察使用.getProperty（）方法时state不在list中尤其是取值失败时的情况
        str = capitals.getProperty("Florida", "Not Found");
        System.out.println("The capital of Florida is "
                + str + ".");
    }
}
